package yijy.game;

/**
 * Created by yijy on 2017/10/17.
 */
import java.io.*;
import javax.swing.*;
import java.awt.event.*;
import java.util.*;
import java.awt.*;

class Game_2048
{
    public static void main(String [] args)
    {
        Ck ck=new Ck();
        ck.scck();


    }



}

    class Ck//窗口
    {
        JFrame jf= new  JFrame("测试窗口");


        JButton button=new JButton("按钮");//生成按钮1
        JButton button2=new JButton("按钮1");//生成按钮2
        JTextField text=new JTextField();//生成文本框1
        JTextField text2=new JTextField();//生成文本框2
        JButton button3=new JButton("上一页");//上一页按钮
        JButton button4=new JButton("下一页");//下一页按钮
        JPanel jp=new JPanel(){

            public void paintComponent(Graphics s)
            {
                System.out.println("被重写111");
                ImageIcon icon=new ImageIcon("c:\\123.jpg");
                s.drawImage(icon.getImage(),0,0,400,200,jf);

            }


        };//生成自定义容器




        public void scck()
        {


            scJpanel(jp);
            text.setVisible(true);//文本框1
            text.setBackground(Color.green);
            text.setBounds(170,200,200,50);

            text2.setVisible(true);//文本框2
            text2.setBackground(Color.red);
            text2.setBounds(370,200,200,50);


            button.setVisible(true);//按钮1
            button.setBackground(Color.lightGray);
            button.setBounds(170,420,200,50);
            button.addActionListener(djbutton());//按钮1监听

            button2.setVisible(true);//按钮2
            button2.setBackground(Color.cyan);
            button2.setBounds(370,420,200,50);
            button2.addActionListener(djbutton2());//按钮2监听

            button3.setVisible(true);
            button3.setBackground(Color.red);
            button3.setBounds(120,110,30,30);
            button3.addActionListener(syybutton());


            button4.setVisible(true);
            button4.setBackground(Color.red);
            button4.setBounds(590,110,30,30);
            button4.addActionListener(xyybutton());

            jf.setVisible(true);
            jf.setSize(800,600);
            jf.setLayout(null);
            jf.add(button);
            jf.add(button2);
            jf.add(text2);
            jf.add(text);
            jf.add(jp);
            jf.add(button3);
            jf.add(button4);

            jf.addWindowListener(new WindowAdapter()  //为了关闭窗口
            {
                public void windowClosing(WindowEvent e)
                {
                    System.exit(0);
                }
            } );






        }

        public ActionListener djbutton2()//监听按钮2
        {
            ActionListener al=new ActionListener()
            {

                public void actionPerformed(ActionEvent ws)
                {
                    String nr=text2.getText();//获取内容
                    System.out.println("按钮2被单机");
                    System.out.println("文本框2"+nr);
                }

            };
            return al;
        }
        public ActionListener djbutton()//监听按钮1
        {
            ActionListener al=new ActionListener()
            {

                public void actionPerformed(ActionEvent ws)
                {
                    String nr=text.getText();
                    System.out.println("按钮1被单机");
                    System.out.println("文本框"+nr);
                }

            };
            return al;
        }

        public ActionListener syybutton()
        {
            ActionListener ls=new ActionListener()
            {
                public void actionPerformed(ActionEvent a)
                {
                    System.out.println("上一页被单机");
                    jp=null;
                    jp=new JPanel(){

                        public void paintComponent(Graphics s)
                        {
                            System.out.println("被重写");
                            ImageIcon icon=new ImageIcon("C:\\124.jpg");
                            s.drawImage(icon.getImage(),0,0,400,200,jf);

                        }

                    };

                    if(jp==null)
                    {

                        System.out.println("kong");
                    }
                    scJpanel(jp,jf);

                }


            };

            return ls;

        }
        public ActionListener xyybutton()
        {
            ActionListener al=new ActionListener()
            {
                public void actionPerformed(ActionEvent s)
                {
                    System.out.println("下一页被单机");


                }
            };
            return al;

        }

        public void scJpanel(JPanel jp)
        {
            jp.setVisible(true);//自定义容器
            jp.setBounds(170,20,400,200);
            jp.setBackground(Color.orange);

        }
        public void scJpanel(JPanel jp,JFrame jf)
        {
            System.out.println("中转被调用");
            jp.setVisible(true);//自定义容器
            jp.setBounds(170,20,410,160);
            jp.setBackground(Color.orange);
            jf.add(jp);
        }
    }
/* class scjpanel extends JPanel//窗口
{

	public Graphics gp;
	public JFrame jf;

	public void paintComponent(Graphics gs)
	{
		Graphics2D s=(Graphics2D)gs.create();
		ImageIcon icon=new ImageIcon("C:\\123.jpg");
		System.out.println("99");
		if(gs==null)
		{

			System.out.println("jfkong ");
		}
		else{System.out.println("bujong ");}
		s.drawImage(icon.getImage(),0,0,400,160,jf);


	}
	public void  csh(JFrame jf)
	{

		this.jf=jf;

	}


}
 */

